<template>
    <h2>会员权益录入</h2>
    <table>
    <tr>
        <th>
            会员权益名称
        </th>
        <th>
            <input type="text" placeholder="请输入会员权益名称"  v-model="Info.MR_Name">
        </th>
    
    
    </tr>
    
    <tr>
        <th>
            会员权益说明
        </th>
        <th>
            <input type="text" placeholder="请输入会员权益说明" v-model="Info.MR_Info">
        </th>
    
    
    </tr>
    
    
    <tr>
        <th>
            是否自定义
        </th>
        <th>
            <input type="radio" value="true"  v-model="Info.MR_IsCustion">是
            <input type="radio" value="false"   v-model="Info.MR_IsCustion">否
        </th>
    
    
    </tr>
    
    
    
    <tr>
        <th>
            规则类型
        </th>
        <th>
            <select  v-model="Info.MR_RuleType">
                <option :value="-1">===请选择===</option>
                <option :value="0">折扣</option>
                <option :value="1">延时</option>
                <option :value="2">餐饮</option>
            </select>
        </th>
    
    
    </tr>
    
    
    <tr>
        <th>
            会员权益规则
        </th>
        <th>
            <textarea cols="20" rows="4" placeholder="请输入会员权益规则" v-model="Info.MR_Rule"></textarea>
        </th>
    
    
    </tr>
    <tr>
        <th>
         
        </th>
        <th>
           <input type="button" value="修改" @click="AddME"  class="btn btn-success">
        </th>
    
    
    </tr>
    
    
    
    </table>
    
    
    
    </template>
    <script setup lang="ts">
    
  
 

    

    
    onMounted(()=>{


        FanTian();
    })
    import axios from 'axios';
import { onMounted,ref } from 'vue';
  
    import{useRouter,useRoute,createRouter}from'vue-router'

    const route=useRoute();
    const router=useRouter();   

   
     const Info = ref({   //双向绑定
        MR_Id:route.params.MRid, 
        MR_Name:"",
        MR_Info:"",
        MR_IsCustion:"",
        MR_RuleType:-1,
        MR_Rule:"",
    
    
     });
    

     const AddME =()=>{
    
       
     if(Info.value.MR_Name=="")   //名字非空
     {
        alert('姓名不能为空')
        return ;

     }
     var reg =/[\u4e00-\u9fa5]/;
     if(!reg.test(Info.value.MR_Name)) //名字必须中文
     {
        alert('权益名称必须是中文')
        return 

     }

        if( Info.value. MR_Info.length<=5) //权益必须大于五个字
     {
        alert('权益内容必须大于五个字符')
        return ;
     }


     axios.put('https://localhost:7035/api/Member/Xg',Info.value)
     .then //成功
     (res=>{

     
        if(res.data>0)
     {
        alert('修改成功')
        router.push('/Show');
        
     }
     else
     {
        alert('修改失败')
     }
        
     })
     .catch(error=>{    //报错

        alert(error);
     })


            
    
     }
    
    
    

        const FanTian=()=>{

            axios.post('https://localhost:7035/api/Member/FanTian?id='+route.params.MRid)
                    
              .then(res=>{

                  
             console.log(res.data);
         Info.value.MR_Name=res.data.MR_Name,
         Info.value.MR_Info=res.data.MR_Info,
         Info.value.MR_IsCustion=res.data.MR_IsCustion,
         Info.value.MR_RuleType=res.data.MR_RuleType,
         Info.value.MR_Rule=res.data.MR_Rule
       



            })



        }

    
    </script>